/*
 * File    : /src/views/mark/meditor/components/PictureList/tools/utils.js
 * Time    : 2021-09-15 14:46:43
 * Author  : Gray Snail
 * Version : 1.0
 * Contact : shtao2011@sina.com
 * License : Copyright (c) 2021 Gray Snail
 * Desc    : None
 */

import paper from 'paper'
const { Path } = paper

/**
 * 鼠标事件源判断,避免 modal 对话框弹出时的任然触发mouse move 事件
 * @param {} event
 * @returns
 */
export const checkEvent = (event) => {
  return event.event.target === event.tool?.view?.element
}

const assistLineOptions = {
  markType: 'assistLine',
  strokeCap: 'round',
  strokeColor: 'Cyan',
  selectedColor: 'Cyan',
  strokeScaling: false,
  dashArray: [12, 6],
}

export const drawAssistLine = (object, { x, y }, { width, height }) => {
  const horizontal = new Path.Line({ from: [0, y], to: [width, y], ...assistLineOptions })
  const vertical = new Path.Line({ from: [x, 0], to: [x, height], ...assistLineOptions })
  object.assistLine = { horizontal, vertical }
}

export const removeAssistLine = (object) => {
  if (object.assistLine) {
    object.assistLine.horizontal.remove()
    object.assistLine.vertical.remove()
    object.assistLine = null
  }
}
